<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .father {
            position: relative;
            width: 500px;
            height: 500px;
            background-color: pink;
            margin: 100px;
        }

        .son {
            width: 100px;
            height: 100px;
            background-color: purple;
            position: absolute;
            top: 10px;
            left: 10px;
        }
    </style>
    <script src="jQuery.min.js"></script>
</head>

<body>
    <div class="father">
        <div class="son"></div>
    </div>
    <script>
        $(function () {
            //获取距离文档的位置(偏移)
            console.log($(".son").offset());
            console.log($(".son").offset().top);
            // $(".son").offset({
            //     top: 200,
            //     left: 200
            // });
            //获取带有定位的父级位置(偏移) position()
            console.log($(".son").position());
            //这个方法只能获取不能设置偏移
            // $(".son").position({
            //     top: 200,
            //     left: 200
            // });
        });
    </script>
</body>

</html>